package com.example.pages;

import org.openqa.selenium.WebElement; 
import org.openqa.selenium.support.FindBy;

public class LoginPage extends AnyPage {

	@FindBy(id = "loginform")
	public WebElement loginForm;
	
	@FindBy(id = "username")
	public WebElement userNameField;

	@FindBy(name = "password")
	public WebElement passwordFild;

	@FindBy(name = "submit")
	public WebElement loginButton;

	public boolean isOnThisPage() {
			return loginForm.isDisplayed();
		}

	@Override
	void tryToOpen() {
		// TODO Auto-generated method stub
	MyPageFactory.getPage(driver, InternalPage.class).logout();	
	}

	public InternalPage loginWitValidCredentials(String username, String password) {
		userNameField.sendKeys(username);
		passwordFild.sendKeys(password);
		loginButton.click();
		return MyPageFactory.getPage(driver, InternalPage.class);
	}
	
	public void loginWitWrongCredentials(String username, String password) {
		userNameField.sendKeys(username);
		passwordFild.sendKeys(password);
		loginButton.click();
		MyPageFactory.getPage(driver, LoginPage.class);
	}


	public void loginAs(String username, String password) {
		//login
		userNameField.clear();
		userNameField.sendKeys(username);
		passwordFild.clear();
		passwordFild.sendKeys(password);
		loginButton.click();
	}	
	
}
